package com.yami.shop.multishop.controller;

import com.yami.shop.bean.model.User;
import com.yami.shop.bean.param.CouponUserParam;
import com.yami.shop.bean.param.UserManagerParam;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.coupon.common.service.CouponUserService;
import com.yami.shop.security.multishop.util.SecurityUtils;
import com.yami.shop.service.ShopCustomerService;
import com.yami.shop.service.UserService;
import com.yami.shop.user.common.service.UserTagUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lanhai
 */
@RequestMapping("/user")
@RestController
@Tag(name = "用户信息")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private ShopCustomerService shopCustomerService;
    @Autowired
    private UserTagUserService userTagUserService;
    @Autowired
    private CouponUserService couponUserService;

    @GetMapping("/info/{userId}")
    @Operation(summary =  "获取品牌用户信息", description = "获取品牌用户信息")
    public ServerResponseEntity<UserManagerParam> getInfo(@PathVariable("userId") String userId) {
        Long shopId = SecurityUtils.getShopUser().getShopId();
        UserManagerParam userManagerParam = new UserManagerParam();
        User user = userService.getById(userId);
        // 补充用户基础信息
        if (user != null) {
            userManagerParam.setUserId(userId);
            userManagerParam.setNickName(user.getNickName());
            userManagerParam.setStatus(user.getStatus());
            userManagerParam.setPic(user.getPic());
        }

        // 补充优惠券信息
        CouponUserParam couponCountInfo = couponUserService.getCouponCountInfo(userId, shopId);
        userManagerParam.setCouponUserParam(couponCountInfo);
        return ServerResponseEntity.success(userManagerParam);
    }
}
